/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jim
 */
@Entity
@Table(name = "PLAYLIST")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Playlist.findAll", query = "SELECT p FROM Playlist p"),
    @NamedQuery(name = "Playlist.findByIdPlaylist", query = "SELECT p FROM Playlist p WHERE p.idPlaylist = :idPlaylist"),
    @NamedQuery(name = "Playlist.findByNamePlaylist", query = "SELECT p FROM Playlist p WHERE p.namePlaylist = :namePlaylist"),
    @NamedQuery(name = "Playlist.findByDescription", query = "SELECT p FROM Playlist p WHERE p.description = :description"),
    @NamedQuery(name = "Playlist.findByCreationDate", query = "SELECT p FROM Playlist p WHERE p.creationDate = :creationDate")})
public class Playlist implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_PLAYLIST")
    private Integer idPlaylist;
    @Basic(optional = false)
    @Column(name = "NAME_PLAYLIST")
    private String namePlaylist;
    @Basic(optional = false)
    @Column(name = "DESCRIPTION")
    private String description;
    @Basic(optional = false)
    @Column(name = "CREATION_DATE")
    @Temporal(TemporalType.DATE)
    private Date creationDate;
    @JoinTable(name = "SONG_PLAYLIST", joinColumns = {
        @JoinColumn(name = "ID_PLAYLIST", referencedColumnName = "ID_PLAYLIST")}, inverseJoinColumns = {
        @JoinColumn(name = "ID_SONG", referencedColumnName = "ID_SONG")})
    @ManyToMany
    private Collection<Song> songCollection;

    public Playlist() {
    }

    public Playlist(Integer idPlaylist) {
        this.idPlaylist = idPlaylist;
    }

    public Playlist(Integer idPlaylist, String namePlaylist, String description, Date creationDate) {
        this.idPlaylist = idPlaylist;
        this.namePlaylist = namePlaylist;
        this.description = description;
        this.creationDate = creationDate;
    }

    public Integer getIdPlaylist() {
        return idPlaylist;
    }

    public void setIdPlaylist(Integer idPlaylist) {
        Integer oldIdPlaylist = this.idPlaylist;
        this.idPlaylist = idPlaylist;
        changeSupport.firePropertyChange("idPlaylist", oldIdPlaylist, idPlaylist);
    }

    public String getNamePlaylist() {
        return namePlaylist;
    }

    public void setNamePlaylist(String namePlaylist) {
        String oldNamePlaylist = this.namePlaylist;
        this.namePlaylist = namePlaylist;
        changeSupport.firePropertyChange("namePlaylist", oldNamePlaylist, namePlaylist);
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        String oldDescription = this.description;
        this.description = description;
        changeSupport.firePropertyChange("description", oldDescription, description);
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        Date oldCreationDate = this.creationDate;
        this.creationDate = creationDate;
        changeSupport.firePropertyChange("creationDate", oldCreationDate, creationDate);
    }

    @XmlTransient
    public Collection<Song> getSongCollection() {
        return songCollection;
    }

    public void setSongCollection(Collection<Song> songCollection) {
        this.songCollection = songCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPlaylist != null ? idPlaylist.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Playlist)) {
            return false;
        }
        Playlist other = (Playlist) object;
        if ((this.idPlaylist == null && other.idPlaylist != null) || (this.idPlaylist != null && !this.idPlaylist.equals(other.idPlaylist))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "POJOS.Playlist[ idPlaylist=" + idPlaylist + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
